﻿<UserControl x:Class="ModernAudioTagger.Content.ContentFileListRename"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:vm="clr-namespace:ModernAudioTagger.ViewModel"
             xmlns:content="clr-namespace:ModernAudioTagger.Content"
             xmlns:provider="clr-namespace:ModernAudioTagger.Provider"
             xmlns:converter="clr-namespace:ModernAudioTagger.Converter"
             xmlns:helper="clr-namespace:ModernAudioTagger.Helpers"
             xmlns:view="clr-namespace:ModernAudioTagger.View"
             xmlns:mscorlib="clr-namespace:System;assembly=mscorlib"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"             
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.DataContext>
        <Binding Source="{x:Static provider:ViewModelLocator.Instance}" Path="LocalSystemVM" />
    </UserControl.DataContext>

    <UserControl.Resources>
        <converter:FilenameConverter x:Key="filenameConverter" />
        <converter:NullToVisibilityConverter x:Key="nullToVisibilityConverter" />
        <converter:IsEqualOrGreaterThanConverter x:Key="isEqualOrGreaterThanConverter" />                
    </UserControl.Resources>

    <Grid>

        <DockPanel Grid.Column="1" Grid.RowSpan="2" Margin="{StaticResource DefaultTopMargin}">

            <DockPanel.Style>
                <Style TargetType="{x:Type DockPanel}">
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Files.Count, Converter={StaticResource isEqualOrGreaterThanConverter}, ConverterParameter='1'}" Value="True">
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </DockPanel.Style>

            <Expander Header="Expand for more options"
                          DockPanel.Dock="Top">
                <StackPanel>
                    <TextBlock FontSize="{StaticResource SmallFontSize}" Text="Path" Style="{StaticResource Title}" HorizontalAlignment="Center" Margin="{StaticResource DefaultTopMargin}" />

                    <TextBlock             
                                Visibility="{Binding SelectedPath, Converter={StaticResource nullToVisibilityConverter}, ConverterParameter=False}"
                                Height="Auto" 
                                Width="Auto"             
                                FontSize="{StaticResource SmallFontSize}" 
                                HorizontalAlignment="Center" 
                                Margin="{StaticResource DefaultTopMargin}">     
                                <Hyperlink Command="{x:Static view:ViewCommands.OpenFolderLocation}" CommandParameter="{Binding SelectedPath}" >
                                    <TextBlock Text="{Binding SelectedPath}"></TextBlock>
                                </Hyperlink>
                            </TextBlock>
                    <TextBlock Height="Auto" FontSize="{StaticResource SmallFontSize}" HorizontalAlignment="Center" Width="Auto" Margin="{StaticResource DefaultTopMargin}"  Visibility="{Binding SelectedPath, Converter={StaticResource nullToVisibilityConverter}}">
                                <Hyperlink Command="{Binding OpenFolderDialogCommand}">Click here</Hyperlink>
                    </TextBlock>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="{StaticResource DefaultTopMargin}">
                        <TextBlock VerticalAlignment="Center" FontSize="{StaticResource SmallFontSize}" Text="Filter" Style="{StaticResource Title}"  />
                        <ComboBox IsEditable="True" SelectedIndex="0" Text="{Binding SelectedExtension, UpdateSourceTrigger=PropertyChanged}" FontSize="{StaticResource SmallFontSize}" HorizontalAlignment="Center" Margin="{StaticResource DefaultLeftMargin}" Width="200">
                            <ComboBox.ItemsSource>
                                <x:Array Type="{x:Type mscorlib:String}">
                                    <mscorlib:String>*.3gp|*.act|*.AIFF*.|*.aac*.|*.ALAC*.|*.amr*.|*.atrac*.|*.Au*.|*.awb*.|*.dct*.|*.dss*.|*.dvf*.|*.flac*.|*.gsm*.|*.iklax*.|*.IVS*.|*.m4a*.|*.m4p*.|*.mmf*.|*.mp3*.|*.mpc*.|*.msv*.|*.ogg*.|*.Opus*.|*.ra*.|*.raw*.|*.TTA*.|*.vox*.|*.wav*.|*.wma*.|*.wv</mscorlib:String>
                                    <mscorlib:String>*.*</mscorlib:String>
                                </x:Array>
                            </ComboBox.ItemsSource>
                            <ComboBox.InputBindings>
                                <KeyBinding Key="Enter" Command="{Binding RefreshFilelistCommand}" />
                            </ComboBox.InputBindings>
                        </ComboBox>
                    </StackPanel>
                </StackPanel>
            </Expander>

            <ListView                      
                    FontSize="{StaticResource SmallFontSize}" 
                    ItemsSource="{Binding Files}"  
                    SelectionMode="Extended"    
                    VirtualizingStackPanel.IsVirtualizing="False"
                    helper:ListBoxMultipleSelectorHelper.SelectedItems="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=RenameVM.SelectedFiles, Mode=TwoWay}"            
                    >
                <ListView.Resources>
                    <ContextMenu x:Key="ItemContextMenu">
                        <MenuItem Header="Open folder location" CommandParameter="{Binding FileName}" Command="{Binding Source={x:Static view:ViewCommands.OpenFolderLocation}}">
                            <MenuItem.Icon>
                                <Path Fill="#FF2B2B2B"
                                      Width="14.3775"
                                      Height="14"
                                      Canvas.Left="0.311264"
                                      Canvas.Top="0.500005"
                                      Stretch="Uniform"
                                      Data="{StaticResource openFolderPathData}"
                                      />
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="Play file" CommandParameter="{Binding FileName}" Command="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=MainVM.PlayFileCommand}">
                            <MenuItem.Icon>
                                <Path Fill="#FF2B2B2B"
                                      Width="14.3775"
                                      Height="14"
                                      Canvas.Left="0.311264"
                                      Canvas.Top="0.500005"
                                      Stretch="Uniform"
                                      Data="{StaticResource playPathData}"
                                      />
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="Rename target" Command="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=RenameVM.RenameObjectCommand}">
                            <MenuItem.Icon>
                                <Path Fill="#FF2B2B2B"
                                      Width="14.3775"
                                      Height="14"
                                      Canvas.Left="0.311264"
                                      Canvas.Top="0.500005"
                                      Stretch="Uniform"
                                      Data="{StaticResource pencilPathData}"
                                      />
                            </MenuItem.Icon>
                        </MenuItem>
                    </ContextMenu>
                </ListView.Resources>
                <!--<ListView.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Select all items" CommandParameter="{Binding FileName}" Command="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=RenameVM.SelectAllItemsCommand}"></MenuItem>
                    </ContextMenu>
                </ListView.ContextMenu>-->
                <ListView.ItemContainerStyle>
                    <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
                        <Setter Property="ContextMenu" Value="{StaticResource ItemContextMenu}" />
                    </Style>
                </ListView.ItemContainerStyle>
                <ListView.View>
                    <GridView>
                        <GridViewColumn>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <mui:ModernButton EllipseDiameter="16" IconWidth="8" IconHeight="8" IconData="{StaticResource playPathData}" CommandParameter="{Binding FileName}" Command="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=MainVM.PlayFileCommand}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Header="Name" DisplayMemberBinding="{Binding FileName, Converter={StaticResource filenameConverter}}" Width="250" />
                    </GridView>
                </ListView.View>

                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <i:InvokeCommandAction Command="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=RenameVM.ShowFileTagCommand}" />
                        <i:InvokeCommandAction Command="{Binding Source={x:Static provider:ViewModelLocator.Instance}, Path=RenameVM.PreviewPatternCommand}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>

            </ListView>
        </DockPanel>

        <StackPanel HorizontalAlignment="Center" Grid.Column="1" Grid.RowSpan="2" Margin="{StaticResource DefaultTopMargin}">
            <StackPanel.Style>
                <Style TargetType="{x:Type StackPanel}">
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Files.Count}" Value="0">
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </StackPanel.Style>
            <TextBlock HorizontalAlignment="Center">List is empty</TextBlock>
            <TextBlock  HorizontalAlignment="Center" Margin="0, 5, 0, 0">
                    <Hyperlink Command="{Binding OpenFolderDialogCommand}">Click here</Hyperlink>
            </TextBlock>
        </StackPanel>

    </Grid>
</UserControl>
